// components/team-icon-five/index.ts
const roleCounts: RoleCounts = {
  坦克: 5,
  输出: 3,
  治疗: 7
};
const Position: { [key: string]: number } = {
  "坦克": 1,
  "输出": 2,
  "治疗": 3
};
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    peopleList:{
      type:Array,
      value:[]
    },
    characters:{
      type:Array,
      value:[]
    },
    
  },
  observers:{
    peopleList:function(value){
        this.clearData()
        if(value){
          value.forEach((element,index) => {
            let careerKey:string =  "imageList["+index+"].career";
            let giftKey:string =  "imageList["+index+"].gift";
             this.setData({
                [careerKey]:element.career,
                [giftKey]:element.position
             })
          });
         let sortArray =  this.data.imageList.sort((a, b) => {
            return (Position[a.position] - Position[b.position])
          });
          console.log("排序之后的顺序",sortArray)
          this.setData({
            "imageList":sortArray
         })
        }
      
    },
    characters:function(value){
      this.clearData()
      // console.log("天赋专精图片组",value)
      if(value){
        // console.log("处理图片数据",value);
        value.forEach((element,index) => {
          let careerKey:string =  "imageList["+index+"].career";
          let giftKey:string =  "imageList["+index+"].gift";
          let nameKey:string =  "imageList["+index+"].name";
          let positionKey:string =  "imageList["+index+"].position";
           this.setData({
              [careerKey]:element.career,
              [giftKey]:element.gift,
              [nameKey]:element.name.split("-")[0],
              [positionKey]:element.position
           })
        });
        let sortArray =  this.data.imageList.sort((a, b) => {
          return (Position[a.position] - Position[b.position])
        });
     
        this.setData({
          "imageList":sortArray
       })
        // console.log("处理图片结果",this.data.imageList);
      }
  }
  },
  /**
   * 组件的初始数据
   */
  data: {
    imageList:[
      {
        career:"",
        gift:"",
        position:"",
      },
      {
        career:"",
        gift:"",
        position:"",
      },
      {
        career:"",
        gift:"",
        position:"",
      },
      {
        career:"",
        gift:"",
        position:"",
      },
      {
        career:"",
        gift:"",
        position:"",
      }
    ],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    clearData(){
      this.setData({
        imageList:[
          {
            career:"",
            gift:"",
            position:""
          },
          {
            career:"",
            gift:"",
            position:""
          },
          {
            career:"",
            gift:"",
            position:""
          },
          {
            career:"",
            gift:"",
            position:""
          },
          {
            career:"",
            gift:"",
            position:""
          }]
      })
    }
  }
})